package com.sky.controller.admin;

import com.sky.dto.DataOverViewQueryDTO;
import com.sky.result.Result;
import com.sky.service.impl.StatisticsServiceImpl;
import com.sky.vo.OrderReportVO;
import com.sky.vo.SalesTop10ReportVO;
import com.sky.vo.TurnoverReportVO;
import com.sky.vo.UserReportVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.HashMap;

@RequestMapping("/admin/report")
@RestController
@Slf4j
public class StatisticsController {
    @Autowired
    private StatisticsServiceImpl statisticsService;

    /**
     * 统计营业额
     *
     * @param dataOverViewQueryDTO 开始时间和结束时间
     * @return
     */
    @GetMapping("/turnoverStatistics")
    public Result ordersStatistics(@Param("begin") String begin ,@Param("end") String end) {
        TurnoverReportVO stringDoubleHashMap = statisticsService.ordersStatistics(begin, end);
        return Result.success(stringDoubleHashMap);
    }

    /**
     * 用户数量统计
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/userStatistics")
    public Result<UserReportVO> userStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end) {
        UserReportVO userReportVO = statisticsService.userStatis(begin, end);
        return Result.success(userReportVO);

    }

    /**
     * 订单统计
     * @param begin
     * @param end
     * @return
     */

    @GetMapping("/ordersStatistics")
    public Result<OrderReportVO> ordersStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end) {
        OrderReportVO orderReportVO = statisticsService.ordersStatis(begin, end);
        return Result.success(orderReportVO);
    }
    @GetMapping("/top10")
    public Result<SalesTop10ReportVO> top10Statistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end){
        SalesTop10ReportVO salesTop10ReportVO = statisticsService.selectTop10(begin, end);
        return Result.success(salesTop10ReportVO);
    }
}
